package com.zone.infrastructure.persistent.po;

import com.zone.domain.strategy.model.entity.StrategyRuleEntity;
import lombok.Data;

import java.util.Date;
import java.util.Objects;

/**
 * @author: zongzi
 * @description: 策略规则
 * @date: 2024/5/20
 */
@Data
public class StrategyRule {

    /** 自增ID */
    private Long id;
    /** 抽奖策略ID */
    private Long strategyId;
    /** 抽奖奖品ID【规则类型为策略，则不需要奖品ID】 */
    private Integer awardId;
    /** 抽象规则类型；1-策略规则、2-奖品规则 */
    private Byte ruleType;
    /** 抽奖规则类型【rule_random - 随机值计算、rule_lock - 抽奖几次后解锁、rule_luck_award - 幸运奖(兜底奖品)】 */
    private String ruleModel;
    /** 抽奖规则比值 */
    private String ruleValue;
    /** 抽奖规则描述 */
    private String ruleDesc;
    /** 创建时间 */
    private Date createTime;
    /** 更新时间 */
    private Date updateTime;

    // 转换成实体对象
    public static StrategyRuleEntity convert2Entity(StrategyRule strategyRule) {
        if (Objects.isNull(strategyRule)) {
            return null;
        }
        StrategyRuleEntity strategyRuleEntity = new StrategyRuleEntity();
        strategyRuleEntity.setStrategyId(strategyRule.getStrategyId());
        strategyRuleEntity.setAwardId(strategyRule.getAwardId());
        strategyRuleEntity.setRuleType(strategyRule.getRuleType());
        strategyRuleEntity.setRuleModel(strategyRule.getRuleModel());
        strategyRuleEntity.setRuleValue(strategyRule.getRuleValue());
        strategyRuleEntity.setRuleDesc(strategyRule.getRuleDesc());
        return strategyRuleEntity;
    }
}
